/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once

#include "../EventManager.h"

class IRender;
namespace gui
{

/**
========================
Manage the GUI subsystem
========================
*/
class Component;
class ComponentUI;


class GUI_Manager : public IEventListener
{
public:

    /** Get the one instance -- Really shouldn't be a singleton - TODO make
        this better!  I Like the singleton now mainly for use from LUA.

        Something to think about:
            Send Events to EvntMng telling a GUI_Listener what todo,
            Ex. Create a dialogbox 100x200, with this text, etc.
     */
    static GUI_Manager* GetInstance() { return instance; };
    /** Add/Remove component */
    void AddComponent( Component* c ) { m_components.push_back( c ); };
    void RemoveComponent( Component* c );

    /** Get a component */
    Component* GetParentComponent( Component* c ) const;
    /** Get a component */
    Component* GetParentComponent( const std::string &name ) const;

    /** Push to front */
    void PushToFront( Component* c );
    void PushToFront( const std::string &name );

    /** un/Install the component UI */
    void InstallUI( ComponentUI* ui );
    void UnistallUI();

    /** Update this component */
    void Update( float dt );
    /** Render the components */
    void Render( IRender* r );

    /** Pump input, feed the input until
        we hit an active component
     */
    void PumpInput();

    /* ---------- IEventListener Interface ----------------*/

    /* Get the Name of the Listener */
    std::string GetName()   { return "guilistener"; };
    /** Get Listener Type - Events this listener listens too */
    int GetListenerType()   { return LT_GUI; };

    /** Handle an event */
    bool HandleEvent( IEvent* e );

private:
    GUI_Manager(void);

    /** Activate components */
    void SetStatusOfComponents( std::vector<std::string> &list, int status );

    typedef std::vector<Component*> type_ComponentList;
    type_ComponentList  m_components;

    // our one instance
    static GUI_Manager* instance;

public:
    virtual ~GUI_Manager(void);
};

/*------------------------------
    GUI activation event
-------------------------------*/
class ActivationEvent : public IEventData
{
public:
    ActivationEvent( std::vector<std::string> &list, int typ ) : m_list(list), type(typ) {};
    // list of comp to activate
    std::vector<std::string> m_list;
    int type;
    IEventData* Copy() { return new ActivationEvent(m_list, type); };
    static const int ACTIVATE = 0;
    static const int DEACTIVATE = 1;

    virtual ~ActivationEvent() {IEventData::~IEventData();};

};

};
